import {def} from "./utils.js";
import defineReactive from "./defineReactive.js";
import observe from "./observe.js";
import {arrayMethods} from './array.js'
import Dep from "./Dep.js";
export default class Observer{
    constructor(value) {
        this.dep = new Dep()
        def(value,'__ob__',this,false)

        if (Array.isArray(value)) {
            // 如果是数组，要非常强行的蛮干：将这个数组的原型，指向arrayMethods
            Object.setPrototypeOf(value, arrayMethods);
            // 让这个数组变的observe
            this.observeArray(value);
        } else {
            this.walk(value);
        }
    }
    walk(value){
        for(let key in value){
            defineReactive(value,key)
        }
    }
    observeArray(arr){
        for (let i = 0, l = arr.length; i < l; i++) {
                // 逐项进行observe
            observe(arr[i]);
        }
    }


}